<template>
  <el-card class="attr_card">
    <el-form :inline="true">
      <!-- 一级分类 -->
      <el-form-item label="一级分类:">
        <el-select
          :disabled="!scene"
          v-model="categoryStore.c1Id"
          @change="handler1"
        >
          <el-option
            :value="item.id"
            v-for="item in categoryStore.c1Arr"
            :key="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- 二级分类 -->
      <el-form-item label="二级分类:">
        <el-select
          :disabled="!scene"
          v-model="categoryStore.c2Id"
          @change="handler2"
        >
          <el-option
            :value="item.id"
            v-for="item in categoryStore.c2Arr"
            :key="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- 三级分类 -->
      <el-form-item label="三级分类:">
        <el-select :disabled="!scene" v-model="categoryStore.c3Id">
          <el-option
            :value="item.id"
            v-for="item in categoryStore.c3Arr"
            :key="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
import { onMounted } from "vue";
import useCategoryStore from "@/store/modules/category";
// 接收父组件传递过来scene
defineProps(["scene"]);
let categoryStore = useCategoryStore();
onMounted(() => {
  // 获取一级分类的数据
  getC1();
});
// 通知仓库获取一级分类的方法
const getC1 = async () => {
  await categoryStore.getC1();
};
// 一级分类下拉菜单的change事件
const handler1 = async () => {
  // 需要将二三级分类清空
  categoryStore.c2Id = null;
  categoryStore.c3Id = null;
  await categoryStore.getC2();
};
// 二级分类下拉菜单的change事件
const handler2 = async () => {
  // 需要将三级分类清空
  categoryStore.c3Id = null;
  await categoryStore.getC3();
};
</script>
<style scoped lang="scss">
.el-form-item {
  margin-top: 6px;
  margin-bottom: 6px;
}
</style>
